package com.cooge.sharevideo.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cooge.sharevideo.base.BaseController;
import com.cooge.sharevideo.web.pojo.Episode;
import com.cooge.sharevideo.web.pojo.EpisodeVideo;
import com.cooge.sharevideo.web.pojo.Menu;
import com.cooge.sharevideo.web.pojo.Video;
import com.cooge.sharevideo.web.service.EpisodeService;
import com.cooge.sharevideo.web.service.EpisodeVideoService;
import com.cooge.sharevideo.web.service.MenuService;
import com.cooge.sharevideo.web.service.VideoService;
/**
 * 视频显示
 * @author 楚平
 *
 */
@Controller
@RequestMapping("v_show")
public class ShowViewController  extends BaseController{
	
	@Autowired
	VideoService videoService;
	@Autowired
	EpisodeVideoService episodeVideoService;
	@Autowired
	MenuService menuService;
	@Autowired
	EpisodeService episodeService;
	
	@RequestMapping(value = "show_{id}.html",method=RequestMethod.GET)
	public ModelAndView goshow(Model model,@PathVariable Long id){
		
		ModelAndView mav=new ModelAndView("v_show/show");
		Video video =	videoService.getVideoById(id);
		model.addAttribute("video", video);
		List<EpisodeVideo> list = episodeVideoService.getlistByVideoId(video.getId());
		
		model.addAttribute("list",list);
		Episode episode = episodeService.getById(list.get(0).getEpisodeId());
		model.addAttribute("episode",episode);
		
		Menu	menu  = menuService.getMenuByEpisodeId(episode.getId());
		model.addAttribute("menu",menu);
		
		return mav;
	}
}
